<?php

namespace App\Services;


/**
 * 处理excel导出数组Hanlde
 * Class HandleDataService
 * @package Core\Services
 */

class HandleDataService
{

    /**
     * 处理PC端通话列表导出数组处理
     * @param $data
     * @return mixed
     */
    public function handleCallExportData($data)
    {
        foreach ($data as $key => $value){
            $keywordStr = '';
            if(!empty($value['key_words'])){
                $keywordsData = json_decode($value['key_words'],true);
                foreach ($keywordsData as $k => $v){
                    $keywordStr .= ','.$v['keyword']. "(".$v['count'] . ")";
                }
                $keywordStr = trim($keywordStr,',');
            }
            $data[$key]['call_time'] =  date('Y-m-d H:i:s',$value['call_time']);
            $data[$key]['keywords_str'] = $keywordStr;
            $data[$key]['duration'] = gmdate("H:i:s", $value['spend_time']);;
            unset($data[$key]['key_words'], $data[$key]['spend_time']);
        }
        return $data;

    }

    public function handleTime($data)
    {
        foreach ($data as $key => $value){
            $data[$key]['created_at'] =  date('Y-m-d H:i:s',$value['created_at']);
        }
        return $data;

    }

    public function handleRecord($data)
    {
        foreach ($data as $key => $value){
            foreach ($value as $kk => $vv){
                if (strpos($kk, 'cord_')){
                    for ($x=1; $x<=10; $x++) {
                        $str = $value['record_' . $x] == 0 ? "否" : '是';
                        $data[$key]['record_' . $x] = $str;
                    }
                }

            }
        }
        return $data;
    }
}